#!/usr/bin/env python
#-*- coding: utf-8 -*-

def flatten(nested):
	try:
		# 不要迭代類似字串的對象
		try: nested + ''
		except TypeError: pass
		else: raise TypeError
		for sublist in nested:
			for element in flatten(sublist):
				yield element
	except TypeError:
		yield nested
		
if __name__ == '__main__':
	nested = ['abc', [1, 2, 3], [4, 5, [6, 7], 'hello']]
	for a in flatten(nested):
		print a